//
//  LeftDrawerViewController.m
//  SimpleNote
//
//  Created by mac on 2017/11/21.
//  Copyright © 2017年 上海LOL信息技术服务有限公司. All rights reserved.
//

#import "LeftDrawerViewController.h"
#import <UIViewController+MMDrawerController.h>
#import "MessageViewController.h"
#import "AboutUsViewController.h"

@interface LeftDrawerViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong) UITableView *tableview;
@property (nonatomic,strong) NSArray *dataArray;

@end

static NSString *MarketListTableViewCellID = @"MarketListTableViewCellID";


@implementation LeftDrawerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupUI];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark ----  UITableViewDelegate/UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MarketListTableViewCellID forIndexPath:indexPath];
    cell.textLabel.text = NSLocalizedString(self.dataArray[indexPath.row],nil);
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    //拿到我们的LitterLCenterViewController，让它去push
    BaseNavigationController* nav = (BaseNavigationController*)self.mm_drawerController.centerViewController;

    if (indexPath.row == 0) {
        MessageViewController *message = [[MessageViewController alloc]init];
        [nav pushViewController:message animated:NO];
    }else if (indexPath.row == 1){
        AboutUsViewController *about = [[AboutUsViewController alloc]init];
        [nav pushViewController:about animated:YES];
    }else if (indexPath.row == 2){
        SRGoToAppStore;
    }else{
    }
    
    //当我们push成功之后，关闭我们的抽屉
    [self.mm_drawerController closeDrawerAnimated:YES completion:^(BOOL finished) {
        //setting打开抽屉模式为MMOpenDrawerGestureModeNone，也就是没有任何效果。
        [self.mm_drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeNone];
    }];
    
}

#pragma mark --- setup UI
-(void)setupUI{
    
    if (@available(iOS 11.0, *)) {
        self.tableview.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    
    [self.view addSubview:self.tableview];
    [self.tableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.view);
        make.top.equalTo(self.view).offset(NavigationBarHeight);
    }];
}

#pragma mark --- set get

-(UITableView *)tableview{
    if (_tableview == nil) {
        _tableview = [[UITableView alloc]init];
        _tableview.delegate = self;
        _tableview.dataSource = self;
        [_tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:MarketListTableViewCellID];
        _tableview.tableFooterView = [[UIView alloc]init];
    }
    return _tableview;
}

-(NSArray *)dataArray{
    if (_dataArray == nil) {
        _dataArray = [NSMutableArray arrayWithObjects:@"Message center",@"About us",@"Encourage us", nil];
    }
    return _dataArray;
}



@end






